package financial.sharing.center.system.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import financial.sharing.center.common.enums.ResponseContext;
import financial.sharing.center.common.utils.PageSize;
import financial.sharing.center.common.utils.R;
import financial.sharing.center.system.model.entity.BusinessLine;
import financial.sharing.center.system.service.BusinessLineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @ClassName BusinessLineController
 * @Description TODO
 * @Author guoyuhang
 * @ @csdn https://blog.csdn.net/qq_40788718
 * @Date 2021/5/7
 * @Version 1.0
 */
@RestController
@RequestMapping(value = "/system/business/line/")
public class BusinessLineController {

    @Autowired
    private BusinessLineService businessLineServiceImpl;

    @PostMapping(value = "get/all/business/line")
    public R getAllBusinessLine(String selectBusinessLineName,
                                String selectSubCompany,
                                String selectDepartment,
                                Integer currentPage){
        PageHelper.startPage(currentPage, PageSize.PAGESIZE_TEN);
        PageInfo<BusinessLine> result = this.businessLineServiceImpl.getAllBusinessLine(selectBusinessLineName,selectSubCompany,selectDepartment);
        return R.ok(result);
    }

    @PostMapping(value = "create/one/business/line")
    public R createOneBusinessLine(String businessLineName,
                                   String subCompany,
                                   String department,
                                   String note){
        Integer result = this.businessLineServiceImpl.createOneBusinessLine(businessLineName, subCompany, department, note);
        return R.ok(ResponseContext.int2Enum(result).getName());
    }

    @PostMapping(value = "compile/one/business/line")
    public R compileOneBusinessLine(@RequestBody BusinessLine businessLine){
        Integer result = this.businessLineServiceImpl.compileOneBusinessLine(businessLine);
        return R.ok(ResponseContext.int2Enum(result).getName());
    }

    @PostMapping(value = "delete/one/business/line")
    public R deleteOneBusinessLine(Integer id){
        Integer result = this.businessLineServiceImpl.deleteOneBusinessLine(id);
        return R.ok(ResponseContext.int2Enum(result).getName());
    }

    @PostMapping(value = "get/list/business/line")
    public R getListBusinessLine(){
        List<BusinessLine> result = this.businessLineServiceImpl.getListBusinessLine();
        return R.ok(result);
    }

    @PostMapping(value = "get/map/business/line")
    public Map<Integer,String> getMapBusinessLine(){
        return this.businessLineServiceImpl.getMapBusinessLine();
    }
}
